package net.thermetics.fx.services;

import java.io.IOException;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xquery.XQException;

import org.apache.http.client.ClientProtocolException;

import net.thermetics.fx.auth.GaeUser;
import net.thermetics.fx.model.ForumThread;

/**
 * Interface that specifies the service for managing thread model
 * objects. 
 * @author projectmoon
 *
 */
public interface ThreadService {
	/**
	 * Returns all forum threads found in the datastore.
	 * @return The list of all forum threads.
	 */
	public List<ForumThread> getAllThreads();
	
	/**
	 * Returns a detached copy of the ForumThread object specified by thread ID.
	 * @param threadID The thread ID to look up.
	 * @return A detached thread object if found, null otherwise.
	 * @throws XQException 
	 */
	public ForumThread getThread(String threadID) throws ClientProtocolException, IOException, ParserConfigurationException, XQException;
	
	/**
	 * Creates an empty thread with the specified ID.
	 * @param threadID
	 * @return A new detached thread object.
	 */
	public ForumThread createThread(String threadID);
	
	/**
	 * Creates a new thread object with the specified ID and list of participants.
	 * @param threadID
	 * @param participants
	 * @return A new detached thread object.
	 */
	public ForumThread createThread(String threadID, List<GaeUser> participants);
	
	/**
	 * Updates an existing detached thread by sending it back to the datastore.
	 * @param thread The thread to persist.
	 * @return true if successful, false otherwise.
	 */
	public boolean updateThread(ForumThread thread);
	
	/**
	 * Deletes the thread specified by threadID.
	 * @param threadID The thread ID to delete.
	 * @return true if the deletion was successful, false if there was an error or the thread was not found.
	 */
	public boolean deleteThread(String threadID);
}
